package model.tokens;

import java.util.Stack;

import model.semantics.IfElseNode;
import model.semantics.Node;

public class IfElseToken extends NodeToken<Integer> {

	public IfElseToken(String label) {
		super(label);
	}

	@Override
	public Node<Integer> makeNewInstance(Stack<Node<Integer>> nodes) {
		Node<Integer> elseNode = (Node<Integer>) nodes.pop();
		Node<Integer> ifNode = (Node<Integer>) nodes.pop();
		Node<Integer> expr = (Node<Integer>) nodes.pop();
		
		return new IfElseNode(expr, ifNode, elseNode);
	}

	@Override
	public void process(Stack<Token<Integer>> operatorStack,
			Stack<Node<Integer>> output) {
		shuntFunctionsToOutput(operatorStack, output);
		
		operatorStack.push(this);
	}

}
